package microassembler;

import java.io.*;
import java.util.Hashtable;

class symbolTable extends Hashtable
{

    symbolTable(String s)
    {
        numErrors = 0;
        numWarnings = 0;
        BufferedReader bufferedreader;
        try
        {
            bufferedreader = new BufferedReader(((java.io.Reader) (new FileReader(s))));
        }
        catch(Exception exception)
        {
            System.out.println("Error: Unable to open input file (" + s + ")");
            return;
        }
        try
        {
            int i = 0;
            int j = -1;
            String s1;
            while((s1 = bufferedreader.readLine()) != null) 
            {
                i++;
                s1 = s1.trim();
                if(!s1.startsWith("#") && s1.length() > 0)
                {
                    if(s1.startsWith("*"))
                    {
                        j = Integer.parseInt(s1.substring(1)) - 1;
                    } else
                    {
                        j++;
                        try
                        {
                            microinst microinst1 = new microinst(s1);
                            if(microinst1.getLineLabel() != null)
                            {
                                Integer integer = (Integer)((Hashtable)this).put(((Object) (microinst1.getLineLabel())), ((Object) (new Integer(j))));
                                if(integer != null)
                                {
                                    System.out.println("[ " + i + " ] Warning: Duplicate label" + globals.ENDL + "\t" + microinst1.getLineLabel() + " appears at address " + integer.intValue() + " and also at address " + j + globals.ENDL + "\t\t" + microinst1.getLineLabel() + "'s value set to " + j);
                                    numWarnings++;
                                }
                            }
                        }
                        catch(InvalidMicroInstException invalidmicroinstexception)
                        {
                            System.out.println("[ " + i + " ] Error: " + invalidmicroinstexception.cause);
                            numErrors++;
                        }
                    }
                }
            }
        }
        catch(IOException ioexception)
        {
            System.out.println(((Object) (ioexception)));
        }
        try
        {
            bufferedreader.close();
        }
        catch(IOException ioexception1)
        {
            System.out.println("Error: Unable to close input file (" + s + ")");
            numErrors++;
        }
    }

    public int getErrorCount()
    {
        return numErrors;
    }

    public int getWarningCount()
    {
        return numWarnings;
    }

    private int numErrors;
    private int numWarnings;
}
